package demo1;


import java.util.concurrent.CountDownLatch;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Main m = new Main();
        int n = Runtime.getRuntime().availableProcessors();
        CountDownLatch cd = new CountDownLatch(n);
        for (int i = 0; i < n; i++) {
            int finalI = i;
            Thread t = new Thread(
                    () -> {
                        m.helloWorld(finalI);
                        cd.countDown();
                    }
            );
            t.start();
        }
        cd.await();
        System.out.println("done");
    }

    public void helloWorld(int i) {
        System.out.println("hello world:" + i);
    }
}
